package com.gitee.wsl.doc.prosemirror.model.content

import com.gitee.wsl.doc.prosemirror.model.node.NodeType

class TokenStream(
    val string: String,
    val nodeTypes: Map<String, NodeType>
) {
    var inline: Boolean? = null
    var pos = 0
    val tokens: MutableList<String> =
        string.split("""\s*(?=\b|\W|$)""".toRegex()).filter { it.isNotEmpty() }.toMutableList()

    val next: String?
        get() = this.tokens.getOrNull(this.pos)

    fun eat(tok: String): Boolean {
        return (next == tok).apply { if (this) pos++ }
    }

    fun err(str: String) {
        throw IllegalStateException("SyntaxError: $str (in content expression '$string')")
    }
}